
//
//  HomeButtonsView.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/22.
//  Copyright © 2016年 zonten. All rights reserved.
//

#import "CommunityButtonsView.h"
#import "UIButton+ButtonStyle.h"
#import "YHMarcros.h"


static CGFloat kMargin = 10;
@interface CommunityButtonsView ()
@property(nonatomic, strong)UIButton *m_btnOpenDoor;
@property(nonatomic, strong)UIButton *m_btnAnnouncement;
@property(nonatomic, strong)UIButton *m_btnPropertycosts;
@property(nonatomic, strong)UIButton *m_btnPark;
@property(nonatomic, strong)UIButton *m_btnPassport;
@property(nonatomic, strong)UIButton *m_btnVolunteerserv;
@property(nonatomic, strong)UIButton *m_btnPension;
@property(nonatomic, strong)UIButton *m_btnAffairs;
@end
@implementation CommunityButtonsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
        self.userInteractionEnabled = NO;
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.m_btnOpenDoor];
    [self.m_btnOpenDoor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.25);
        make.height.equalTo(self).multipliedBy(0.5);
    }];

    [self addSubview:self.m_btnAnnouncement];
    [self.m_btnAnnouncement mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.equalTo(self.m_btnOpenDoor);
        make.leading.equalTo(self.m_btnOpenDoor.trailing);
    }];
    
    [self addSubview:self.m_btnPropertycosts];
    [self.m_btnPropertycosts mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.equalTo(self.m_btnOpenDoor);
        make.leading.equalTo(self.m_btnAnnouncement.trailing);
    }];
    
    [self addSubview:self.m_btnPark];
    [self.m_btnPark mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.equalTo(self.m_btnOpenDoor);
        make.leading.equalTo(self.m_btnPropertycosts.trailing);
    }];
    
    [self addSubview:self.m_btnPassport];
    [self.m_btnPassport mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m_btnOpenDoor.bottom);
        make.width.height.leading.equalTo(self.m_btnOpenDoor);
    }];
    
    [self addSubview:self.m_btnVolunteerserv];
    [self.m_btnVolunteerserv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.top.equalTo(self.m_btnPassport);
        make.leading.equalTo(self.m_btnPassport.trailing);
    }];
    
    [self addSubview:self.m_btnPension];
    [self.m_btnPension mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.top.equalTo(self.m_btnPassport);
        make.leading.equalTo(self.m_btnVolunteerserv.trailing);
    }];
    [self addSubview:self.m_btnAffairs];
    [self.m_btnAffairs mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.top.equalTo(self.m_btnPassport);
        make.leading.equalTo(self.m_btnPension.trailing);
    }];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.m_btnOpenDoor layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kIphoneSize_Height(kMargin)];
    [self.m_btnAnnouncement layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kMargin];
    [self.m_btnPropertycosts layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kMargin];
    [self.m_btnPark layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kMargin];
    
    [self.m_btnPassport layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kMargin];
    [self.m_btnAffairs layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kMargin];
    [self.m_btnVolunteerserv layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kMargin];
    [self.m_btnPension layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleTop imageTitleSpace:kMargin];
}

- (void)buttonClick:(UIButton *)button
{
    if (!self.delegate || ![self.delegate respondsToSelector:@selector(communityButtonsViewDidClick:)])
    {
        return;
    }
    [self.delegate communityButtonsViewDidClick:button.tag];
    
}
#pragma mark - lazy loading

- (UIButton *)m_btnOpenDoor
{
    if (!_m_btnOpenDoor) {
        _m_btnOpenDoor = [[UIButton alloc]init];
        [_m_btnOpenDoor setImage:[UIImage imageNamed:@"community_icon_opendoor"] forState:UIControlStateNormal];
        [_m_btnOpenDoor setImage:[UIImage imageNamed:@"community_icon_opendoor"] forState:UIControlStateHighlighted];
        [_m_btnOpenDoor setTitle:@"开门" forState:UIControlStateNormal];
        [_m_btnOpenDoor setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnOpenDoor.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnOpenDoor.tag = 0;
        [_m_btnOpenDoor addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnOpenDoor;
}
- (UIButton *)m_btnAnnouncement
{
    if (!_m_btnAnnouncement) {
        _m_btnAnnouncement = [[UIButton alloc]init];
        [_m_btnAnnouncement setImage:[UIImage imageNamed:@"community_icon_announcement"] forState:UIControlStateNormal];
        [_m_btnAnnouncement setImage:[UIImage imageNamed:@"community_icon_announcement"] forState:UIControlStateHighlighted];
        [_m_btnAnnouncement setTitle:@"小区公告" forState:UIControlStateNormal];
        [_m_btnAnnouncement setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnAnnouncement.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnAnnouncement.tag = 1;
        [_m_btnAnnouncement addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnAnnouncement;
}
- (UIButton *)m_btnPropertycosts
{
    if (!_m_btnPropertycosts) {
        _m_btnPropertycosts = [[UIButton alloc]init];
        [_m_btnPropertycosts setImage:[UIImage imageNamed:@"community_icon_propertycosts"] forState:UIControlStateNormal];
        [_m_btnPropertycosts setImage:[UIImage imageNamed:@"community_icon_propertycosts"] forState:UIControlStateHighlighted];
        [_m_btnPropertycosts setTitle:@"物业缴费" forState:UIControlStateNormal];
        [_m_btnPropertycosts setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnPropertycosts.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnPropertycosts.tag = 2;
        [_m_btnPropertycosts addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnPropertycosts;
}

- (UIButton *)m_btnPark
{
    if (!_m_btnPark) {
        _m_btnPark = [[UIButton alloc]init];
        [_m_btnPark setImage:[UIImage imageNamed:@"community_icon_parking"] forState:UIControlStateNormal];
        [_m_btnPark setImage:[UIImage imageNamed:@"community_icon_parking"] forState:UIControlStateHighlighted];
        [_m_btnPark setTitle:@"智能停车" forState:UIControlStateNormal];
        [_m_btnPark setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnPark.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnPark.tag = 3;
        [_m_btnPark addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnPark;
}
- (UIButton *)m_btnPassport
{
    if (!_m_btnPassport) {
        _m_btnPassport = [[UIButton alloc]init];
        [_m_btnPassport setImage:[UIImage imageNamed:@"community_icon_passport"] forState:UIControlStateNormal];
        [_m_btnPassport setImage:[UIImage imageNamed:@"community_icon_passport"] forState:UIControlStateHighlighted];
        [_m_btnPassport setTitle:@"访客通行" forState:UIControlStateNormal];
        [_m_btnPassport setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnPassport.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnPassport.tag = 4;
        [_m_btnPassport addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnPassport;
}
- (UIButton *)m_btnAffairs
{
    if (!_m_btnAffairs) {
        _m_btnAffairs = [[UIButton alloc]init];
        [_m_btnAffairs setImage:[UIImage imageNamed:@"community_icon_affairs"] forState:UIControlStateNormal];
        [_m_btnAffairs setImage:[UIImage imageNamed:@"community_icon_affairs"] forState:UIControlStateHighlighted];
        [_m_btnAffairs setTitle:@"智慧政务" forState:UIControlStateNormal];
        [_m_btnAffairs setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnAffairs.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnAffairs.tag = 5;
        [_m_btnAffairs addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnAffairs;
}
- (UIButton *)m_btnVolunteerserv
{
    if (!_m_btnVolunteerserv) {
        _m_btnVolunteerserv = [[UIButton alloc]init];
        [_m_btnVolunteerserv setImage:[UIImage imageNamed:@"community_icon_volunteerservice"] forState:UIControlStateNormal];
        [_m_btnVolunteerserv setImage:[UIImage imageNamed:@"community_icon_volunteerservice"] forState:UIControlStateHighlighted];
        [_m_btnVolunteerserv setTitle:@"志愿服务" forState:UIControlStateNormal];
        [_m_btnVolunteerserv setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnVolunteerserv.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnVolunteerserv.tag = 6;
        [_m_btnVolunteerserv addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnVolunteerserv;
}
- (UIButton *)m_btnPension
{
    if (!_m_btnPension) {
        _m_btnPension = [[UIButton alloc]init];
        [_m_btnPension setImage:[UIImage imageNamed:@"community_icon_pension"] forState:UIControlStateNormal];
        [_m_btnPension setImage:[UIImage imageNamed:@"community_icon_pension"] forState:UIControlStateHighlighted];
        [_m_btnPension setTitle:@"智慧养老" forState:UIControlStateNormal];
        [_m_btnPension setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _m_btnPension.titleLabel.font = [UIFont systemFontOfSize:14];
        _m_btnPension.tag = 7;
        [_m_btnPension addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnPension;
}
@end
